<template>
  <div>
    <el-table
      :data="list"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="菜单编号"> </el-table-column>
      <el-table-column prop="title" label="菜单名称"> </el-table-column>
      <el-table-column prop="icon" label="菜单图标">
        <template slot-scope="scope">
          <div>
            <i :class="scope.row.icon"></i>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="菜单地址"> </el-table-column>
      <el-table-column prop="type" label="状态">
        <template slot-scope="scope">
          <div>
            <el-button type="info" v-if="scope.row.status == 1">启用</el-button>
            <el-button type="warning" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button type="success" @click="bianji(scope.row.id)">编辑</el-button>
            <el-button type="primary" @click="del(scope.row.id)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { mapActions, mapGetters } from "vuex";
import {menudelete} from '../../../request/api'
import {successAlert,warningAlert} from '../../../util/alert'
export default {
  data() {
    return {};
  },
  methods: {
    ...mapActions({
      reqchangelist: "menu/reqchangelist",
    }),
    // 删除
    del(id) {
        this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          menudelete({id:id}).then(res=>{
              if(res.data.code==200){
                  successAlert(res.data.msg)
                //   刷新列表
                  this.reqchangelist()
              }else{
                  warningAlert(res.data.msg)
              }
          })
        }).catch(() => {
            warningAlert('已取消删除')
        });

    },
    // 编辑
    bianji(id){
        this.$emit('bianji',id)
    }
  },
  mounted() {
    this.reqchangelist();
  },
  computed: {
    ...mapGetters({
      list: "menu/list",
    }),
  },
};
</script>

<style lang="less" scoped>
</style>